package org.qqcui.designpattern.patterns.state;

/**
 * 中奖，发送奖品状态
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/7 14:18
 **/
public class DispenseState extends State {

    private RaffleActivity activity;

    public DispenseState(RaffleActivity activity) {
        this.activity = activity;
    }

    @Override
    void deduceScore() {
        System.out.println("抽中奖品了，等待发奖");
    }

    @Override
    boolean raffle() {
        System.out.println("抽中奖品了，等待发奖");
        return false;
    }

    @Override
    void dispensePrize() {
        if (activity.getCount() > 0) {
            // 还有奖品，可以发奖
            System.out.println("恭喜你中奖了，等待发奖");
            // 设置为不能抽奖状态
            activity.setState(activity.getNoRaffleState());
        } else {
            // 奖品已经发完了
            System.out.println("奖品被抽完了，期待下次活动吧");
            // 设置为奖品抽完状态
            activity.setState(activity.getDispenseOutState());
        }
    }
}
